<?php defined( '_JEXEC' ) or die( 'Restricted access' ); 

class TableVote extends JTable
{
  var $id = null;
  var $sketchup_id = null;
  var $ip_address = null;
  var $session_id = null;
  var $time = null;

	function __construct(&$db)
	{
		parent::__construct( '#__sketchup_votes', 'id', $db );
	}

  /**
   * Returns false (don't allow) if the current IP address or session ID has
   * voted in the last 24 hours
   *
   * @return void
   * @author Joseph LeBlanc
   */
	function check()
	{
    $db =& JFactory::getDBO();

    $day_ago = time() - 86400;

    $query = "SELECT count(*) FROM #__sketchup_votes"
    . " WHERE (ip_address = " . $db->Quote($this->ip_address) . " AND session_id = " . $db->Quote($this->session_id) . ")"
    . " AND time > '{$day_ago}'";
    $db->setQuery($query);
    $votes = $db->loadResult();

    if ($votes > 0) {
      return false;
    }

    return true;
  }
}